#include "STC8A8K64D4.h"
#include "LED4BITMODULE.H"
unsigned char LEDBUF[4]={1,2,3,4};
//共阳极 位码
#ifdef pLED
	unsigned char  pDigitalBitTable[]={0x10,0x20,0x40,0x80};
#else
	unsigned char  pDigitalBitTable[]={0xe0,0xd0,0xb0,0x70};
#endif
//pDigitalFontTable[]共阳极数码管的段码
unsigned char code pDigitalFontTable[]={
	0xc0,//0
	0xf9,//1
	0xa4,//2
	0xb0,//3
	0x99,//4
	0x92,//5
	0x82,//6
	0xf8,//7
	0x80,//8
	0x90,//9
	0x88,//A
	0x83,//B
	0xc6,//C
	0xa1,//D
	0x86,//E
	0x8e, //F
	0x80, //.
	0xc1,//U
	0x91,//Y
	0x7c,//L
	0x00,//全亮
	0xff,  //全灭
	0x40  // -
};




void LEDModule_BeepON(unsigned char onoff)
{
	unsigned char i;
	if(onoff)
	{
		for(i=0;i<4;i++)
		{	
			pDigitalBitTable[i]=pDigitalBitTable[i]|0x01;
		}
	}
	else
	{
		for(i=0;i<4;i++)pDigitalBitTable[i]=pDigitalBitTable[i]&0xfe;
	}
}

void LEDModule_LEDON(unsigned char onoff)
{
		unsigned char i;
	if(onoff)
	{
		for(i=0;i<4;i++)
		{
			pDigitalBitTable[i]=pDigitalBitTable[i]|0x02;
		}
	}
	else
	{
		for(i=0;i<4;i++)pDigitalBitTable[i]=pDigitalBitTable[i]&0xfd;
	}
}
//dat msb first
void LEDModule_SendByte(unsigned char Odat)
{
	unsigned char i,Mask;
	Mask=0x80;
	for(i=0;i<8;i++)
	{
		mLED_74HC595_SHCP=0;
		if((Odat&Mask)==0)mLED_74HC595_DAT=0;
		else mLED_74HC595_DAT=1;
		Mask>>=1;		
		mLED_74HC595_SHCP=1;
	}
	 
}
// Bdat :位选
// Odat ：数据
// dotbit:数码管小数点是否量
// 位选数据在前
void LEDModule_Sendat(unsigned char LEDBit,unsigned charLEDValue, char dotbit)
{ 
	mLED_74HC595_LACP=0;
#ifdef pLED	//共阳数码管
  LEDModule_SendByte(pDigitalBitTable[LEDBit]);	
	LEDModule_SendByte(pDigitalFontTable[charLEDValue]);
#else
	LEDModule_SendByte(pDigitalBitTable[LEDBit]);	
	LEDModule_SendByte(~pDigitalFontTable[charLEDValue]);
#endif
	mLED_74HC595_LACP=1;	
}
void LEDModule_Sendat2(unsigned char LEDBit,unsigned charLEDValue, char dotbit)
{ 
	mLED_74HC595_LACP=0;	 
  LEDModule_SendByte(pDigitalBitTable[LEDBit]);	
  if((dotbit<4&& dotbit>-1)&& (LEDBit==dotbit))
		LEDModule_SendByte(pDigitalFontTable[charLEDValue]&(~pDigitalFontTable[16]));		
  else 			LEDModule_SendByte(pDigitalFontTable[charLEDValue]|pDigitalFontTable[16]);
	
	mLED_74HC595_LACP=1;	
	
		 
}

